<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryForm" :model="queryParams" label-width="80px">
          <el-row :gutter="24">
            <el-col :span="8">
              <div class="timebox">
                <el-form-item label="日期时间" prop="date">
                  <timer
                    flag="T"
                    ref="timer"
                    :timer.sync="queryParams.date"
                    @query="IntHandle"
                  ></timer>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="4">
              <el-form-item label="操作类型" prop="type">
                <el-select
                  v-model="queryParams.type"
                  placeholder="请选择"
                  filterable
                  @change="getList"
                >
                  <el-option
                    v-for="item in TypeOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="发卡门店" prop="storeId">
                <el-select
                  v-model="queryParams.storeId"
                  placeholder="请选择"
                  filterable
                  @change="handleQuery"
                >
                  <el-option
                    v-for="(item, index) in $store.state.user.stores"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="消费门店" prop="storeIdSub">
                <el-select
                  v-model="queryParams.storeIdSub"
                  placeholder="请选择"
                  filterable
                  @change="getList"
                >
                  <el-option
                    v-for="(item, index) in $store.state.user.stores"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="会员卡号" prop="cardNumber">
                <el-input
                  v-model="queryParams.cardNumber"
                  class="w-300"
                  placeholder="请输入会员卡号"
                  @keyup.enter.native="getList"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="手机号" prop="mobile">
                <el-input
                  v-model="queryParams.mobile"
                  class="w-300"
                  placeholder="请输入手机号"
                  @keyup.enter.native="getList"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="账单号" prop="orderNo">
                <el-input
                  class="w-200 text-left"
                  v-model="queryParams.orderNo"
                  placeholder="账单号查询"
                  @keyup.enter.native="getList"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <div style="margin-left: -90px">
                <el-form-item label="异常赠送" prop="statementErrStatus">
                  <el-select
                    v-model="queryParams.statementErrStatus"
                    placeholder="请选择"
                    filterable
                    style="width: 180px"
                  >
                    <el-option
                      v-for="item in statementErrStatusOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>

    <div class="MoneyBox">
      <div>
        变动余额:
        <span style="color: red"
          >￥{{ MemberTradingTotal.statementTotalMoney }}</span
        >
      </div>
      <div>
        变动本金:
        <span style="color: red"
          >￥{{ MemberTradingTotal.statementPrincipal }}</span
        >
      </div>
      <div>
        变动赠金:
        <span style="color: red"
          >￥{{ MemberTradingTotal.statementGiveMoney }}</span
        >
      </div>
    </div>

    <div class="table_card">
      <!-- 上部分 title -->
      <div class="table_card_top">
        <span class="solid_left1"></span>
        <div class="table_card_title">储值交易记录</div>
        <div class="op_right">
          <el-button
            @click="handleExport"
            :loading="exportLoading"
            class="repeat"
            >导出</el-button
          >
        </div>
      </div>

      <div class="table_list">
        <el-table
          :data="MemberTradingList"
          stripe
          style="width: 100%"
          v-loading="loading"
          :row-class-name="tableRowClassName"
          :cell-style="tableCellstyle"
        >
          <el-table-column prop="chargingTime" label="账单时间" width="180px">
          </el-table-column>
          <el-table-column prop="orderNo" label="关联账单" width="180px">
          </el-table-column>
          <el-table-column prop="createName" label="操作员工" width="120px">
          </el-table-column>
          <el-table-column prop="cardStoreName" label="发卡门店" width="220px">
          </el-table-column>
          <el-table-column prop="storeName" label="消费门店" width="220px">
          </el-table-column>
          <el-table-column prop="customerName" label="客户姓名" width="120px">
          </el-table-column>
          <el-table-column prop="typeDesc" label="操作类型" width="120px">
          </el-table-column>
          <el-table-column
            prop="customerMobile"
            label="客户手机号"
            width="120px"
          >
          </el-table-column>
          <el-table-column prop="cardNumber" label="会员卡号" width="130px">
          </el-table-column>
          <el-table-column
            prop="statementPrincipal"
            label="变动本金"
            width="130px"
          >
          </el-table-column>
          <el-table-column
            prop="statementGiveMoney"
            label="变动赠金"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="surplusPrincipal"
            label="结余本金"
            width="120px"
          >
          </el-table-column>
          <el-table-column
            prop="surplusGiveMoney"
            label="结余赠金"
            width="120px"
          >
          </el-table-column>
          <el-table-column prop="surplusBalance" label="卡片余额">
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
import {
  getStatementPageList,
  getStatementPageListTotal,
  ExcelpageList,
} from "@/api/business/MemberTrading";
import timer from "@/components/getTime/timer";
export default {
  name: "Storeadminmembertrading",
  components: { timer },
  data() {
    return {
      MemberTradingList: [],
      MemberTradingTotal: {}, // 统计记录
      loading: false,
      value: "",
      // 查询参数
      queryParams: {
        cardNumber: "",
        mobile: "",
        orderNo: "",
        storeId: "",
        storeIdSub: "", // 消费门店
        type: "",
        pageNo: 1,
        pageSize: 10,
        storeId: "",
        date: [],
        startDate: "",
        endDate: "",
        statementErrStatus: "", //  Y:是;N:否
      },
      timecache: [],
      total: 0,
      exportLoading: false,
      TypeOptions: [
        {
          value: 1,
          label: "充值",
        },
        {
          value: 2,
          label: "消费",
        },
        {
          value: 3,
          label: "钱包调整",
        },
        {
          value: 4,
          label: "会员卡转账-转入",
        },
        {
          value: 5,
          label: "会员卡转账-转出",
        },
        {
          value: 6,
          label: "退卡",
        },
        {
          value: 7,
          label: "订单返结账",
        },
        {
          value: 8,
          label: "充值反结账",
        },
        {
          value: 9,
          label: "预约支付",
        },
        {
          value: 10,
          label: "预约取消",
        },
        {
          value: 11,
          label: "预约回退",
        },
        {
          value: 12,
          label: "退卡回退",
        },
      ],

      statementErrStatusOptions: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ],
    };
  },

  mounted() {},

  created() {},

  methods: {
    tableRowClassName(row, rowIndex) {
      console.log(row, "列表行");

      if (row.row.statementErrStatus === "Y") {
        return "rowColor";
      }
      return "";
    },
    tableCellstyle(row, rowIndex) {
      if (row.row.statementErrStatus === "Y") {
        return "background:  #e94f5e";
      }
      return "";
    },
    handleExport() {
      this.$modal
        .confirm("是否确认导出储值交易记录?")
        .then(() => {
          this.exportLoading = true;
          let queryParams = JSON.parse(JSON.stringify(this.queryParams));

          if (!!this.queryParams.date) {
            queryParams.startDate = this.queryParams.date[0];
            queryParams.endDate = this.queryParams.date[1];
          }
          delete queryParams.date;
          return ExcelpageList(queryParams);
        })
        .then((response) => {
          this.$download.excel(response, "储值交易记录");
          this.exportLoading = false;
        })
        .catch(() => {
          this.exportLoading = false;
        });
    },
    IntHandle(e) {
      console.log(e, "dls");
      this.timecache = JSON.parse(JSON.stringify(this.queryParams.date));
      this.handleQuery();
    },

    // 筛选
    handleQuery() {
      console.log("dksf");

      this.queryParams.pageNo = 1;
      this.getList();
      this.getStatementPageTotal();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryForm");
      this.$nextTick(() => {
        this.queryParams.date = JSON.parse(JSON.stringify(this.timecache));
      });
    },

    // 表单重置
    resetFormData(formName) {
      console.log(this.$refs[formName]);
      this.$nextTick(() => {
        this.$refs[formName].resetFields();
      });
    },

    // 储值交易记录
    getList() {
      let query = JSON.parse(JSON.stringify(this.queryParams));
      console.log("query", query);

      if (!!query.date && query.date.length > 0) {
        query.startDate = this.queryParams.date[0];
        query.endDate = this.queryParams.date[1];
        delete query.date;
      } else {
        this.$message.error("日期时间不能为空");
        return false;
      }
      this.loading = true;
      getStatementPageList(query)
        .then((res) => {
          console.log(res);
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.MemberTradingList = data.list;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    getStatementPageTotal() {
      let queryData = JSON.parse(JSON.stringify(this.queryParams));

      if (!!queryData.date && queryData.date.length > 0) {
        queryData.startDate = this.queryParams.date[0];
        queryData.endDate = this.queryParams.date[1];
        delete queryData.date;
      } else {
        return false;
      }
      getStatementPageListTotal(queryData)
        .then((res) => {
          const { code, data } = res;
          if (code === 0) {
            this.MemberTradingTotal = data;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.solid_left1 {
  margin-left: 24px;
}
.goodTop {
  width: 100%;
  height: 48px;
  background: #ffffff;
  display: flex;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.6);
  line-height: 48px;
  padding-left: 16px;
  .good_list {
    margin-right: 32px;
  }

  .good_active {
    color: #0052d9;
    border-bottom: 1px solid #0052d9;
  }
}

.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}

.Order_box {
  display: flex;
  margin-left: -50px;
  .select_ipt {
    width: 130px;
    margin-right: 10px;
  }
}

.pay_ipt {
  margin-left: 50px;
}

.order_ipt {
  margin-left: -120px;
}

.timebox {
  margin-top: 10px;
}
.MoneyBox {
  height: 50px;
  line-height: 50px;
  background-color: #fff;
  margin: 0 24px;
  display: flex;
  font-weight: bold;
  font-size: 16px;
  div {
    margin-right: 50px;
    margin-left: 10px;
  }
}

::v-deep .el-table .rowColor {
  background: #e94f5e;
}
</style>
